<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta name="Content-Type" content="text/html; charset=utf-8" />
<title>Class: Thinner::Client</title>
<link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="../css/common.css" type="text/css" media="screen" charset="utf-8" />

<script type="text/javascript" charset="utf-8">
  relpath = '..';
  if (relpath != '') relpath += '/';
</script>
<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>

  </head>
  <body>
    <script type="text/javascript" charset="utf-8">
      if (window.top.frames.main) document.body.className = 'frames';
    </script>
    
    <div id="header">
      <div id="menu">
  
    <a href="../_index.html">Index (C)</a> &raquo; 
    <span class='title'><span class='object_link'><a href="../Thinner.html" title="Thinner (module)">Thinner</a></span></span>
     &raquo; 
    <span class="title">Client</span>
  
  
  <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
</div>

      <div id="search">
  <a id="class_list_link" href="#">Class List</a>
  <a id="method_list_link" href="#">Method List</a>
  <a id ="file_list_link" href="#">File List</a>
</div>

      <div class="clear"></div>
    </div>
    
    <iframe id="search_frame"></iframe>
    
    <div id="content"><h1>Class: Thinner::Client
  
  
  
</h1>

<dl class="box">
  
    <dt class="r1">Inherits:</dt>
    <dd class="r1">
      <span class="inheritName">Object</span>
      
        <ul class="fullTree">
          <li>Object</li>
          
            <li class="next">Thinner::Client</li>
          
        </ul>
        <a href="#" class="inheritanceTree">show all</a>
      
      </dd>
    
  
  
    
  
    
  
  
  
    <dt class="r2 last">Defined in:</dt>
    <dd class="r2 last">lib/thinner/client.rb</dd>
  
</dl>
<div class="clear"></div>

<h2>Overview</h2><div class="docstring">
  <div class="discussion">
    <p>
A Thinner::Client runs as a background process and purges a list of urls in
batches.
</p>


  </div>
</div>
<div class="tags">
  
</div>
  <h2>Constant Summary</h2>
  
    <dl class="constants">
      
        <dt id="ERRORS-constant" class="">ERRORS =
          <div class="docstring">
  <div class="discussion">
    <p>
The list of Errors we want to catch.
</p>


  </div>
</div>
<div class="tags">
  
</div>
        </dt>
        <dd><pre class="code"><span class='lbrack token'>[</span><span class='Varnish constant id'>Varnish</span><span class='colon2 op'>::</span><span class='Error constant id'>Error</span><span class='comma token'>,</span> <span class='Varnish constant id'>Varnish</span><span class='colon2 op'>::</span><span class='BrokenConnection constant id'>BrokenConnection</span><span class='comma token'>,</span> <span class='Varnish constant id'>Varnish</span><span class='colon2 op'>::</span><span class='CommandFailed constant id'>CommandFailed</span><span class='comma token'>,</span> <span class='Timeout constant id'>Timeout</span><span class='colon2 op'>::</span><span class='Error constant id'>Error</span><span class='comma token'>,</span> <span class='Errno constant id'>Errno</span><span class='colon2 op'>::</span><span class='ECONNREFUSED constant id'>ECONNREFUSED</span><span class='rbrack token'>]</span>
</pre></dd>
      
    </dl>
  


  <h2>Instance Attribute Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2>
  <ul class="summary">
    
      <li class="public ">
  <span class="summary_signature">
    
      <a href="#purged_urls-instance_method" title="#purged_urls (instance method)">- (Object) <strong>purged_urls</strong> </a>
    

    
  </span>
  
  
    <span class="note title readonly">readonly</span>
    
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'><p>
A list of successfully purged urls.
</p>
</div></span>
  
</li>

    
  </ul>


  
    <h2>
      Instance Method Summary
      <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
    </h2>

    <ul class="summary">
      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#close_log-instance_method" title="#close_log (instance method)">- (Object) <strong>close_log</strong> </a>
    

    
  </span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'><p>
Log the purged urls and exit the process.
</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#handle_errors-instance_method" title="#handle_errors (instance method)">- (Object) <strong>handle_errors</strong> </a>
    

    
  </span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'><p>
Trap certain signals so the Client can report back the progress of the job
and close the log.
</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#initialize-instance_method" title="#initialize (instance method)">- (Client) <strong>initialize</strong>(urls) </a>
    

    
  </span>
  
    <span class="note title constructor">constructor</span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'><p>
Before purging, each Thinner::Client grabs various configuration settings
and makes a copy of the passed in urls.
</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#logger-instance_method" title="#logger (instance method)">- (Object) <strong>logger</strong> </a>
    

    
  </span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'><p>
The logger redirects all STDOUT writes to a logger instance.
</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#run%21-instance_method" title="#run! (instance method)">- (Object) <strong>run!</strong> </a>
    

    
  </span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'><p>
Kickstart the purging process and loop through the array until there
aren&#8217;t any urls left to purge.
</p>
</div></span>
  
</li>

      
    </ul>
  

<div id="constructor_details" class="method_details_list">
  <h2>Constructor Details</h2>
  
    <div class="method_details first">
  <p class="signature first" id="initialize-instance_method">
  
    - (<tt><span class='object_link'><a href="" title="Thinner::Client (class)">Client</a></span></tt>) <strong>initialize</strong>(urls) 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
Before purging, each Thinner::Client grabs various configuration settings
and makes a copy of the passed in urls.
</p>


  </div>
</div>
<div class="tags">
  
</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


17
18
19
20
21
22
23
24
25
26
27</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/thinner/client.rb', line 17</span>

<span class='def def kw'>def</span> <span class='initialize identifier id'>initialize</span><span class='lparen token'>(</span><span class='urls identifier id'>urls</span><span class='rparen token'>)</span>
  <span class='@batch ivar id'>@batch</span>        <span class='assign token'>=</span> <span class='Thinner constant id'>Thinner</span><span class='dot token'>.</span><span class='configuration identifier id'>configuration</span><span class='dot token'>.</span><span class='batch_length identifier id'>batch_length</span>
  <span class='@timeout ivar id'>@timeout</span>      <span class='assign token'>=</span> <span class='Thinner constant id'>Thinner</span><span class='dot token'>.</span><span class='configuration identifier id'>configuration</span><span class='dot token'>.</span><span class='sleep_time identifier id'>sleep_time</span>
  <span class='@varnish ivar id'>@varnish</span>      <span class='assign token'>=</span> <span class='Varnish constant id'>Varnish</span><span class='colon2 op'>::</span><span class='Client constant id'>Client</span><span class='dot token'>.</span><span class='new identifier id'>new</span> <span class='Thinner constant id'>Thinner</span><span class='dot token'>.</span><span class='configuration identifier id'>configuration</span><span class='dot token'>.</span><span class='server identifier id'>server</span>
  <span class='@log_file ivar id'>@log_file</span>     <span class='assign token'>=</span> <span class='Thinner constant id'>Thinner</span><span class='dot token'>.</span><span class='configuration identifier id'>configuration</span><span class='dot token'>.</span><span class='log_file identifier id'>log_file</span>
  <span class='@purged_urls ivar id'>@purged_urls</span>  <span class='assign token'>=</span> <span class='lbrack token'>[</span><span class='rbrack token'>]</span>
  <span class='@urls ivar id'>@urls</span>         <span class='assign token'>=</span> <span class='Array constant id'>Array</span><span class='dot token'>.</span><span class='new identifier id'>new</span> <span class='urls identifier id'>urls</span>
  <span class='@length ivar id'>@length</span>       <span class='assign token'>=</span> <span class='@urls ivar id'>@urls</span><span class='dot token'>.</span><span class='length identifier id'>length</span>
  <span class='logger identifier id'>logger</span>
  <span class='handle_errors identifier id'>handle_errors</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
  
</div>

  <div id="instance_attr_details" class="attr_details">
    <h2>Instance Attribute Details</h2>
    
      
      <span id=""></span>
      <span id="purged_urls-instance_method"></span>
      <div class="method_details first">
  <p class="signature first" id="purged_urls-instance_method">
  
    - (<tt>Object</tt>) <strong>purged_urls</strong>  <span class="extras">(readonly)</span>
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
A list of successfully purged urls.
</p>


  </div>
</div>
<div class="tags">
  
</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


10
11
12</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/thinner/client.rb', line 10</span>

<span class='def def kw'>def</span> <span class='purged_urls identifier id'>purged_urls</span>
  <span class='@purged_urls ivar id'>@purged_urls</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
  </div>


  <div id="instance_method_details" class="method_details_list">
    <h2>Instance Method Details</h2>
    
    
      <div class="method_details first">
  <p class="signature first" id="close_log-instance_method">
  
    - (<tt>Object</tt>) <strong>close_log</strong> 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
Log the purged urls and exit the process.
</p>


  </div>
</div>
<div class="tags">
  
</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


81
82
83
84</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/thinner/client.rb', line 81</span>

<span class='def def kw'>def</span> <span class='close_log identifier id'>close_log</span>
  <span class='@logger ivar id'>@logger</span><span class='dot token'>.</span><span class='info identifier id'>info</span> <span class='dstring node'>&quot;Purged #{@purged_urls.length} of #{@length} urls.&quot;</span>
  <span class='@logger ivar id'>@logger</span><span class='dot token'>.</span><span class='info identifier id'>info</span> <span class='string val'>&quot;Exiting...&quot;</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="handle_errors-instance_method">
  
    - (<tt>Object</tt>) <strong>handle_errors</strong> 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
Trap certain signals so the Client can report back the progress of the job
and close the log.
</p>


  </div>
</div>
<div class="tags">
  
</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


66
67
68
69
70</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/thinner/client.rb', line 66</span>

<span class='def def kw'>def</span> <span class='handle_errors identifier id'>handle_errors</span>
  <span class='trap identifier id'>trap</span><span class='lparen token'>(</span><span class='string val'>'TERM'</span><span class='rparen token'>)</span> <span class='lbrace token'>{</span> <span class='close_log identifier id'>close_log</span> <span class='rbrace token'>}</span>
  <span class='trap identifier id'>trap</span><span class='lparen token'>(</span><span class='string val'>'KILL'</span><span class='rparen token'>)</span> <span class='lbrace token'>{</span> <span class='close_log identifier id'>close_log</span> <span class='rbrace token'>}</span>
  <span class='trap identifier id'>trap</span><span class='lparen token'>(</span><span class='string val'>'INT'</span><span class='rparen token'>)</span>  <span class='lbrace token'>{</span> <span class='close_log identifier id'>close_log</span> <span class='rbrace token'>}</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="logger-instance_method">
  
    - (<tt>Object</tt>) <strong>logger</strong> 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
The logger redirects all STDOUT writes to a logger instance.
</p>


  </div>
</div>
<div class="tags">
  
</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


73
74
75
76
77
78</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/thinner/client.rb', line 73</span>

<span class='def def kw'>def</span> <span class='logger identifier id'>logger</span>
  <span class='if if kw'>if</span> <span class='notop op'>!</span><span class='@log_file ivar id'>@log_file</span><span class='dot token'>.</span><span class='respond_to? fid id'>respond_to?</span><span class='lparen token'>(</span><span class='symbol val'>:write</span><span class='rparen token'>)</span>
    <span class='STDOUT constant id'>STDOUT</span><span class='dot token'>.</span><span class='reopen identifier id'>reopen</span><span class='lparen token'>(</span><span class='File constant id'>File</span><span class='dot token'>.</span><span class='open identifier id'>open</span><span class='lparen token'>(</span><span class='@log_file ivar id'>@log_file</span><span class='comma token'>,</span> <span class='lparen token'>(</span><span class='File constant id'>File</span><span class='colon2 op'>::</span><span class='WRONLY constant id'>WRONLY</span> <span class='bitor op'>|</span> <span class='File constant id'>File</span><span class='colon2 op'>::</span><span class='APPEND constant id'>APPEND</span> <span class='bitor op'>|</span> <span class='File constant id'>File</span><span class='colon2 op'>::</span><span class='CREAT constant id'>CREAT</span><span class='rparen token'>)</span><span class='rparen token'>)</span><span class='rparen token'>)</span>
  <span class='end end kw'>end</span>
  <span class='@logger ivar id'>@logger</span> <span class='assign token'>=</span> <span class='Logger constant id'>Logger</span><span class='dot token'>.</span><span class='new identifier id'>new</span><span class='lparen token'>(</span><span class='STDOUT constant id'>STDOUT</span><span class='rparen token'>)</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="run!-instance_method">
  
    - (<tt>Object</tt>) <strong>run!</strong> 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
Kickstart the purging process and loop through the array until there
aren&#8217;t any urls left to purge. Each time the loop runs it will update
the process label with the first url in the list.
</p>


  </div>
</div>
<div class="tags">
  
</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


32
33
34
35
36
37
38
39
40</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/thinner/client.rb', line 32</span>

<span class='def def kw'>def</span> <span class='run! fid id'>run!</span>
  <span class='while while kw'>while</span> <span class='@urls ivar id'>@urls</span><span class='dot token'>.</span><span class='length identifier id'>length</span> <span class='gt op'>&gt;</span> <span class='integer val'>0</span>
    <span class='@current_job ivar id'>@current_job</span> <span class='assign token'>=</span> <span class='@urls ivar id'>@urls</span><span class='dot token'>.</span><span class='slice! fid id'>slice!</span> <span class='integer val'>0</span><span class='comma token'>,</span> <span class='@batch ivar id'>@batch</span>
    <span class='$0 gvar id'>$0</span> <span class='assign token'>=</span> <span class='dstring node'>&quot;#{PROCESS_IDENTIFIER}: purging #{@current_job.first}&quot;</span>
    <span class='purge_urls identifier id'>purge_urls</span>
    <span class='sleep identifier id'>sleep</span> <span class='@timeout ivar id'>@timeout</span>
  <span class='end end kw'>end</span>
  <span class='close_log identifier id'>close_log</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
  </div>

</div>
    
    <div id="footer">
  Generated on Mon Nov 22 12:10:39 2010 by 
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
  0.6.1 (ruby-1.8.7).
</div>

  </body>
</html>